package com.xuetang9.fujian.threaddemo;

/**
 * @author: fujian
 * @description:
 * @date: 2021/5/2 16:00
 * @version: V1.0
 * @package: com.xuetang9.fujian.threaddemo
 **/
public class YieldDemo {
    public static void main(String[] args) {
        Thread thread1 = new Thread(new PrintNumTask1(), "打印线程一");
        Thread thread2 = new Thread(new PrintNumTask1(), "打印线程二");

        thread1.start();
        thread2.start();
    }
}
class PrintNumTask1 implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i == 20){
                System.out.println(Thread.currentThread().getName() + "开始礼让");
                Thread.yield();
            }
            System.out.println(Thread.currentThread().getName() + "打印的数字," + i);

        }
    }
}
